home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / systime.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-01  |  6.6 KB  |  224 lines

  1. /* systime.h - System-dependent definitions for time manipulations.
  2.    Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
  3.  
  4. This file is part of XEmacs.
  5.  
  6. XEmacs is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by the
  8. Free Software Foundation; either version 2, or (at your option) any
  9. later version.
  10.  
  11. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14. for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with XEmacs; see the file COPYING.  If not, write to the Free
  18. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Synched up with: FSF 19.28. */
  21.  
  22. #ifndef _XEMACS_SYSTIME_H_
  23. #define _XEMACS_SYSTIME_H_
  24.  
  25. #ifdef TIME_WITH_SYS_TIME
  26. #include <sys/time.h>
  27. #include <time.h>
  28. #else
  29. #ifdef HAVE_SYS_TIME_H
  30. #include <sys/time.h>
  31. #else
  32. #include <time.h>
  33. #endif
  34. #endif
  35.  
  36. #ifdef HAVE_UTIME_H
  37. # include <utime.h>
  38. #endif
  39.  
  40. #ifdef HAVE_TZNAME
  41. #ifndef tzname        /* For SGI.  */
  42. extern char *tzname[];    /* RS6000 and others want it this way.  */
  43. #endif
  44. #endif
  45.  
  46. /* SVr4 doesn't actually declare this in its #include files.  */
  47. #ifdef USG5_4
  48. extern long timezone;
  49. #endif
  50.  
  51. #ifdef VMS
  52. #ifdef VAXC
  53. #include "vmstime.h"
  54. #endif
  55. #endif
  56.  
  57. /* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h
  58.    disagree about the name of the guard symbol.  */
  59. #ifdef HPUX
  60. #ifdef _STRUCT_TIMEVAL
  61. #ifndef __TIMEVAL__
  62. #define __TIMEVAL__
  63. #endif
  64. #endif
  65. #endif
  66.  
  67. /* EMACS_TIME is the type to use to represent temporal intervals.
  68.    At one point this was 'struct timeval' on some systems, int on others.
  69.    But this is stupid.  Other things than select() code like to
  70.    manipulate time values, and so microsecond precision should be
  71.    maintained.  Separate typedefs and conversion functions are provided
  72.    for select().
  73.  
  74.    EMACS_SECS (TIME) is an rvalue for the seconds component of TIME.
  75.    EMACS_SET_SECS (TIME, SECONDS) sets that to SECONDS.
  76.  
  77.    EMACS_USECS (TIME) is an rvalue for the microseconds component of TIME.
  78.    EMACS_SET_USECS (TIME, MICROSECONDS) sets that to MICROSECONDS.
  79.  
  80.    Note that all times are returned in "normalized" format (i.e. the
  81.    usecs value is in the range 0 <= value < 1000000) and are assumed
  82.    to be passed in in this format.
  83.  
  84.    EMACS_SET_SECS_USECS (TIME, SECS, USECS) sets both components of TIME.
  85.  
  86.    EMACS_GET_TIME (TIME) stores the current system time in TIME, which
  87.     should be an lvalue.
  88.  
  89.    set_file_times (PATH, ATIME, MTIME) changes the last-access and
  90.     last-modification times of the file named PATH to ATIME and
  91.     MTIME, which are EMACS_TIMEs.
  92.  
  93.    EMACS_NORMALIZE_TIME (TIME) coerces TIME into normalized format.
  94.  
  95.    EMACS_ADD_TIME (DEST, SRC1, SRC2) adds SRC1 to SRC2 and stores the
  96.     result in DEST.  Either or both may be negative.
  97.  
  98.    EMACS_SUB_TIME (DEST, SRC1, SRC2) subtracts SRC2 from SRC1 and
  99.     stores the result in DEST.  Either or both may be negative.
  100.  
  101.    EMACS_TIME_NEG_P (TIME) is true iff TIME is negative.
  102.  
  103.    EMACS_TIME_EQUAL (TIME1, TIME2) is true iff TIME1 is the same as TIME2.
  104.    EMACS_TIME_GREATER (TIME1, TIME2) is true iff TIME1 is greater than
  105.         TIME2.
  106.    EMACS_TIME_EQUAL_OR_GREATER (TIME1, TIME2) is true iff TIME1 is
  107.         greater than or equal to TIME2.
  108.  
  109. */
  110.  
  111. #ifdef HAVE_TIMEVAL
  112.  
  113. #define EMACS_SELECT_TIME struct timeval
  114. #define EMACS_TIME_TO_SELECT_TIME(time, select_time) ((select_time) = (time))
  115.  
  116. #else /* not HAVE_TIMEVAL */
  117.  
  118. struct timeval
  119. {
  120.   long tv_sec;                /* seconds */
  121.   long tv_usec;               /* microseconds */
  122. };
  123.  
  124. #define EMACS_SELECT_TIME int
  125. #define EMACS_TIME_TO_SELECT_TIME(time, select_time) \
  126.   EMACS_TIME_TO_INT (time, select_time)
  127.  
  128. #endif /* not HAVE_TIMEVAL */
  129.  
  130. #define EMACS_TIME_TO_INT(time, intvar)        \
  131. do {                        \
  132.   EMACS_TIME tmptime = time;            \
  133.                         \
  134.   if (tmpime.tv_usec > 0)            \
  135.     (intvar) = tmptime.tv_sec + 1;        \
  136.   else                        \
  137.     (intvar) = tmptime.tv_sec;            \
  138. } while (0)
  139.  
  140. #define EMACS_TIME struct timeval
  141. #define EMACS_SECS(time)            ((time).tv_sec  + 0)
  142. #define EMACS_USECS(time)            ((time).tv_usec + 0)
  143. #define EMACS_SET_SECS(time, seconds)        ((time).tv_sec  = (seconds))
  144. #define EMACS_SET_USECS(time, microseconds) ((time).tv_usec = (microseconds))
  145.  
  146. #if !defined (HAVE_GETTIMEOFDAY)
  147. struct timezone;
  148. extern int gettimeofday (struct timeval *, struct timezone *);
  149. #endif
  150.  
  151. /* On SVR4, the compiler may complain if given this extra BSD arg.  */
  152. #ifdef GETTIMEOFDAY_ONE_ARGUMENT
  153. # ifdef SOLARIS2
  154. /* Solaris (at least) omits this prototype.  IRIX5 has it and chokes if we
  155.    declare it here. */
  156. extern int gettimeofday (struct timeval *);
  157. # endif
  158. /* According to the Xt sources, some NTP daemons on some systems may
  159.    return non-normalized values. */
  160. #define EMACS_GET_TIME(time)                    \
  161. do {                                \
  162.   gettimeofday (&(time));                    \
  163.   EMACS_NORMALIZE_TIME (time);                    \
  164. } while (0)
  165. #else /* not GETTIMEOFDAY_ONE_ARGUMENT */
  166. #define EMACS_GET_TIME(time)                    \
  167. do {                                \
  168.   struct timezone dummy;                    \
  169.   gettimeofday (&(time), &dummy);                \
  170.   EMACS_NORMALIZE_TIME (time);                    \
  171. } while (0)
  172. #endif /* not GETTIMEOFDAY_ONE_ARGUMENT */
  173.  
  174. #define EMACS_NORMALIZE_TIME(time)                \
  175. do {                                \
  176.   while ((time).tv_usec >= 1000000)                \
  177.     {                                \
  178.       (time).tv_usec -= 1000000;                \
  179.       (time).tv_sec++;                        \
  180.     }                                \
  181.   while ((time).tv_usec < 0)                    \
  182.     {                                \
  183.       (time).tv_usec += 1000000;                \
  184.       (time).tv_sec--;                        \
  185.     }                                \
  186. } while (0)
  187.  
  188. #define EMACS_ADD_TIME(dest, src1, src2)            \
  189. do {                                \
  190.   (dest).tv_sec  = (src1).tv_sec  + (src2).tv_sec;        \
  191.   (dest).tv_usec = (src1).tv_usec + (src2).tv_usec;        \
  192.   EMACS_NORMALIZE_TIME (dest);                    \
  193. } while (0)
  194.  
  195. #define EMACS_SUB_TIME(dest, src1, src2)            \
  196. do {                                \
  197.   (dest).tv_sec  = (src1).tv_sec  - (src2).tv_sec;        \
  198.   (dest).tv_usec = (src1).tv_usec - (src2).tv_usec;        \
  199.   EMACS_NORMALIZE_TIME (dest);                    \
  200. } while (0)
  201.  
  202. #define EMACS_TIME_NEG_P(time) ((long)(time).tv_sec < 0)
  203.  
  204. #define EMACS_TIME_EQUAL(time1, time2)                \
  205.   ((time1).tv_sec == (time2).tv_sec &&                \
  206.    (time1).tv_usec == (time2).tv_usec)
  207.  
  208. #define EMACS_TIME_GREATER(time1, time2)            \
  209.   ((time1).tv_sec > (time2).tv_sec ||                \
  210.    ((time1).tv_sec == (time2).tv_sec &&                \
  211.     (time1).tv_usec > (time2).tv_usec))
  212.  
  213. #define EMACS_TIME_EQUAL_OR_GREATER(time1, time2)        \
  214.   ((time1).tv_sec > (time2).tv_sec ||                \
  215.    ((time1).tv_sec == (time2).tv_sec &&                \
  216.     (time1).tv_usec >= (time2).tv_usec))
  217.  
  218. #define EMACS_SET_SECS_USECS(time, secs, usecs)         \
  219.   (EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs))
  220.  
  221. extern int set_file_times (char *filename, EMACS_TIME atime, EMACS_TIME mtime);
  222.  
  223. #endif /* _XEMACS_SYSTIME_H_ */
  224.